package solitaire.presentation;

import java.awt.*;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.io.IOException;

import javax.swing.*;

import solitaire.controle.CCarte;

//-------------------------------------------------------------------------------------

public class PCarte extends JPanel implements Transferable {

	private static final long serialVersionUID = 1L;

	protected CCarte controle;
	protected JLabel face;
	protected JLabel dos;
	protected ImageIcon icone;

	public PCarte(final String chaine, final CCarte controle) {
		this.controle = controle;
		setLayout(null);
		setBackground(Color.blue);

		icone = new ImageIcon("src/solitaire/img/new/" + chaine + ".png");
		face = new JLabel(icone);
		add(face);
		face.setLocation(0, 0);
		face.setSize(largeur, hauteur);

		ImageIcon iconeDos = new ImageIcon("src/solitaire/img/new/backside.png");
		dos = new JLabel(iconeDos);
		dos.setSize(face.getSize());
		add(dos);
		dos.setLocation(0, 0);

		setOpaque(false);
		setSize(face.getSize());
		setPreferredSize(getSize());
	}

	public void setFaceVisible(boolean faceVisible) {
		face.setVisible(faceVisible);
	}

	public final CCarte getControle() {
		return controle;
	}

//	public void paint(Graphics g) {
//		super.paint(g);
//		g.drawRect(0, 0, getWidth() - 1, getHeight() - 1);
//	}

	public ImageIcon getIcone() {
		return (icone);
	}

	public static int largeur;
	public static int hauteur;

	public static void initDimensions() {
		ImageIcon icone = new ImageIcon("src/solitaire/img/new/1C.png");
		largeur = icone.getIconWidth();
		hauteur = icone.getIconHeight();
	}

	public static void main(String args[]) {
		initDimensions();
		JFrame f = new JFrame("Test PCarte");
		f.getContentPane().add(new PCarte("1C", null));
		f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		f.pack();
		f.setVisible(true);
	}

	@Override
	public DataFlavor[] getTransferDataFlavors() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public boolean isDataFlavorSupported(DataFlavor flavor) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public Object getTransferData(DataFlavor flavor)
			throws UnsupportedFlavorException, IOException {
		// TODO Auto-generated method stub
		return null;
	}
}

// -------------------------------------------------------------------------------------
